package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.aop.annotation.LogAnnotation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.TCzjlEntity;
import com.company.project.service.TCzjlService;



/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-11-29 19:15:55
 */
@Controller
@RequestMapping("/")
public class TCzjlController {
    @Autowired
    private TCzjlService tCzjlService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/tCzjl")
    public String tCzjl() {
        return "tczjl/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("tCzjl/add")
    @RequiresPermissions("tCzjl:add")
    @ResponseBody
    public DataResult add(@RequestBody TCzjlEntity tCzjl){
        tCzjlService.save(tCzjl);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("tCzjl/delete")
    @RequiresPermissions("tCzjl:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tCzjlService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("tCzjl/update")
    @RequiresPermissions("tCzjl:update")
    @ResponseBody
    public DataResult update(@RequestBody TCzjlEntity tCzjl){
        tCzjlService.updateById(tCzjl);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tCzjl/listByPage")
    @RequiresPermissions("tCzjl:list")
    @LogAnnotation(title = "操作记录", action = "查询分页数据")
    @ResponseBody
    public DataResult findListByPage(@RequestBody TCzjlEntity tCzjl){
        Page page = new Page(tCzjl.getPage(), tCzjl.getLimit());
        LambdaQueryWrapper<TCzjlEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TCzjlEntity::getUserid, tCzjl.getUserid());
        queryWrapper.orderByAsc(TCzjlEntity::getCzTime);
        IPage<TCzjlEntity> iPage = tCzjlService.pageList(page, tCzjl);
        return DataResult.success(iPage);
    }

}
